﻿using UnityEngine;
using System.Collections;

public class BlockScript : MonoBehaviour {

    public int hitsToKill;
    public int score;
    private int numOfalreadyHit;


	// Use this for initialization
	void Start () {

        numOfalreadyHit = 0;
	}
	
	// Update is called once per frame
	void Update () {
	    
	}
    //2D碰撞检测
    void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag.Trim() == "Ball".Trim())
        {
            numOfalreadyHit++;

            if (numOfalreadyHit >= hitsToKill)
            {
                GameObject player = GameObject.FindGameObjectsWithTag("Player")[0];
                player.SendMessage("addScore",score);

                Destroy(this.gameObject);
            }
        }
    }
}
